#include <iostream>
#include <vector>
using namespace std;

double power(int a, int b)
{
	double result = 1;
	if (b >= 0)
	{
		for (int i = 0; i < b; i++)
			result *= a;
	}
	else
	{
		for (int i = 0; i > b; i--)
			result = 1.0 * result / a;
	}
	return result;
};

int main()
{
	int beta = 2, p = 3, L = -1, U = 1;
	double UFL = 0, OFL = 0;
	OFL = power(beta, U) * (beta - power(beta, 1 - p));
	UFL = power(beta, L);
	cout << "UFL = " << UFL << ", OFL = " << OFL << endl;

	vector<double> normal, subnormal;
	for (int i = L; i <= U; i++)
	{
		double x = 0;
		for (int j = 0; j < beta; j++)
			for (int k = 0; k < beta; k++)
			{
				x = (2 * (2 + j)) + k;
				x *= power(beta, -2);
				normal.push_back(x * power(2, i));
				normal.push_back(-x * power(2, i));
			}
	}
	normal.push_back(0);

	for (int i = 0; i < beta; i++)
		for (int j = 0; j < beta; j++)
		{
			double x = power(2, L);
			x *= (1.0 * i / 2 + 1.0 * j / 4);
			if (i + j != 0)
			{
				subnormal.push_back(x);
				subnormal.push_back(-x);
			}
		}

	cout << "There are " << normal.size() << " numbers in this normalized FPN system." << endl;
	for (int i = 0; i < normal.size(); i++)
		cout << normal[i] << " ";
	cout << endl;

	cout << "There are " << subnormal.size() << " numbers in this subnormal FPN system." << endl;
	for (int i = 0; i < subnormal.size(); i++)
		cout << subnormal[i] << " ";
	cout << endl;
}
